﻿package baidu.reader.txt.model
{
    import baidu.reader.common.model.*;
    import baidu.ui.managers.*;
    import flash.events.*;
    import flash.net.*;
    import flash.utils.*;

    class TxtRemoteDataProxy extends EventDispatcher
    {
        private var _urlLoader:URLLoader;
        private var _data:ByteArray;

        function TxtRemoteDataProxy(param1:IEventDispatcher = null)
        {
            this._urlLoader = new URLLoader();
            super(param1);
            this._urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            this._urlLoader.addEventListener(Event.COMPLETE, this.dataCompleteHandler);
            this._urlLoader.addEventListener(IOErrorEvent.IO_ERROR, this.errorHandler);
            this._urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.errorHandler);
            return;
        }// end function

        private function errorHandler(event:Event) : void
        {
            dispatchEvent(new Event(ErrorEvent.ERROR));
            return;
        }// end function

        private function dataCompleteHandler(event:Event) : void
        {
            this._data = this._urlLoader.data;
            dispatchEvent(event);
            return;
        }// end function

        public function load(param1:String, param2:int, param3:int) : void
        {
            var _loc_4:* = param2 * param3 + 1;
            var _loc_5:* = (InstanceManager.createSingletonInstance(AppConfigModel) as AppConfigModel).getContentURL(param1, "pn=" + _loc_4 + "&rn=" + param3);
            this._urlLoader.load(new URLRequest(_loc_5));
            return;
        }// end function

        public function get data() : ByteArray
        {
            return this._data;
        }// end function

    }
}
